package Test.code;

import java.io.File;
import java.io.FileWriter;

import Test.tools.Utils;

public class DaoGener {

	public static void daoTest(String tableName,String tableBean,String currentBao) throws Exception{
		 String rn = "\r\n";
		 String []array = Utils.stringToArray(tableBean);
		 String src = 
			"package " + currentBao + ".dao;" + rn +
			"import java.util.List;" + rn +
			"import java.util.Map;" + rn +
			"import " + currentBao + ".bean."+Utils.upperFirstChar(tableName)+";" + rn +
			 rn +
			 rn +
			 "public interface "+Utils.upperFirstChar(tableName)+"Dao {" + rn +
			 rn +
			 "	 //查所有"+ rn +
			 "	 public List<"+Utils.upperFirstChar(tableName)+"> all"+Utils.upperFirstChar(tableName)+"(Map<Object,Object> map);"+ rn +
			 rn +
			 "	 //删除"+ rn +
			 "	 public void del"+Utils.upperFirstChar(tableName)+"(int " +array[0]+ ");"+ rn +
			 rn +
			 "	 //获取一个form"+ rn +
			 "	 public  "+Utils.upperFirstChar(tableName)+ "  "+tableName+"(int  " +array[0]+ ");"+ rn +
			 rn +
			 "	 //修改"+ rn +
			 "	 public void update"+Utils.upperFirstChar(tableName)+ "("+Utils.upperFirstChar(tableName)+ "  "+tableName+");"+ rn +
			 rn +
			 "	 //添加"+ rn +
			 "	 public void add"+Utils.upperFirstChar(tableName)+ "("+Utils.upperFirstChar(tableName)+"  "+tableName+");"+ rn +
			 rn +
			 
			 "	 //查询总条数"+ rn +
			 "	 public int count"+Utils.upperFirstChar(tableName)+"();"+ rn +
			 
			"}"+ rn ;
			
			
		    String path  = System.getProperty("user.dir")+"/src/"+Utils.docToBackslash(currentBao)+"/dao/";
			File fpath = new File(path);
			if (!fpath.exists()) {
			   fpath.mkdirs();
		    }
			String fileName = System.getProperty("user.dir")+"/src/"+Utils.docToBackslash(currentBao)+"/dao/"+Utils.upperFirstChar(tableName)+"Dao.java";
			File f = new File(fileName);
			FileWriter fw = new FileWriter(f);
			fw.write(src);
			fw.flush();
			fw.close();
	 }

	public static void daoTest_(String tableName,String firstTable,String tableBean,String currentBao) throws Exception{
		 String rn = "\r\n";
		 String []array = Utils.stringToArray(tableBean);
		 String src = 
			"package " + currentBao + ".dao;" + rn +
			"import java.util.List;" + rn +
			"import " + currentBao + ".bean."+Utils.upperFirstChar(tableName)+";" + rn +
			 rn +
			 rn +
			 "public interface "+Utils.upperFirstChar(tableName)+"Dao {" + rn +
			 rn +
			 "	 //查所有"+ rn +
			 "	 public List<"+Utils.upperFirstChar(tableName)+"> all"+Utils.upperFirstChar(tableName)+"(String "+firstTable+"Id);"+ rn +
			 rn +
			 "	 //删除"+ rn +
			 "	 public void del"+Utils.upperFirstChar(tableName)+"(int " +array[0]+ ");"+ rn +
			 rn +
			 "	 //获取一个form"+ rn +
			 "	 public  "+Utils.upperFirstChar(tableName)+ "  "+tableName+"(int  " +array[0]+ ");"+ rn +
			 rn +
			 "	 //修改"+ rn +
			 "	 public void update"+Utils.upperFirstChar(tableName)+ "("+Utils.upperFirstChar(tableName)+ "  "+tableName+");"+ rn +
			 rn +
			 "	 //添加"+ rn +
			 "	 public void add"+Utils.upperFirstChar(tableName)+ "("+Utils.upperFirstChar(tableName)+"  "+tableName+");"+ rn +
			 rn +
				
			"}"+ rn ;
			
			
		    String path  = System.getProperty("user.dir")+"/src/"+Utils.docToBackslash(currentBao)+"/dao/";
			File fpath = new File(path);
			if (!fpath.exists()) {
			   fpath.mkdirs();
		    }
			String fileName = System.getProperty("user.dir")+"/src/"+Utils.docToBackslash(currentBao)+"/dao/"+Utils.upperFirstChar(tableName)+"Dao.java";
			File f = new File(fileName);
			FileWriter fw = new FileWriter(f);
			fw.write(src);
			fw.flush();
			fw.close();
	 }

}
